package net.huashitong.scheduling.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import net.huashitong.scheduling.entity.ProjectReserve;
import net.huashitong.scheduling.entity.ProjectSecondRecom;
import net.huashitong.scheduling.entity.ProjectSecondRes;
import net.huashitong.scheduling.filter.ProjectReserveFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ProjectSecondResDao extends StringDao<ProjectSecondRes> {

    public List<ProjectSecondRes> queryType(String type ,ProjectReserveFilter filter){
        GenericQuery query = createQuery("obj");

        query.append(" and obj.month = :month").setParam("month",filter.getMonth());
        query.append(" and obj.year = :year").setParam("year",filter.getYear());
        if("行业".equals(type)) {
            query.append(" and obj.type = :type order by cast(obj.projectInvestment as int) DESC").setParam("type", type);
        }
        if("乡镇".equals(type)){
            query.append(" and obj.type = :type order by cast(obj.score as int) DESC").setParam("type", type);
        }

        return query.listResult();

    }

    public List<ProjectSecondRes> queryByMonthAndYear(String month, String year){
        GenericQuery query = createQuery("obj");
        query.append(" and obj.month = :month").setParam("month",month);
        query.append(" and obj.year = :year").setParam("year",year);
        return query.listResult();
    }
}
